<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!doctype html>
<html>
	<head>
		<title>跑马灯公告</title>
		<base href="<%=basePath%>" />
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="icon" type="image/png" href="i/buyu.ico">
		<meta name="apple-mobile-web-app-title" content="Amaze UI" />
		<link rel="stylesheet" href="layui/css/layui.css">
	</head>

	<body>
	  <br>
	  <div class="layui-input-block">
	    <h2>跑马灯公告</h1>
      </div>
        <form class="layui-form" lay-filter="Runnotice">
		  <div class="layui-form-item layui-form-text">
		      <div class="layui-input-block">
			    <textarea placeholder="最多输入50个字" class="layui-textarea" 
			              name="Content" id="Content" style="width:600px;" 
			              onKeyup="if(this.value.length>0){this.value=this.value.slice(0,50);}">
			    </textarea>
			  </div>
		  </div>
          
          <div class="layui-form-item">
		    <div class="layui-inline">
		      <label class="layui-form-label">播放时长</label>
		      <div class="layui-input-inline">
		        <input type="number" name="Duration" id="Duration" autocomplete="off" class="layui-input" min="1">
		      </div>
		      <div class="layui-form-mid layui-word-aux">默认单位:分钟</div>
		    </div>
		    <div class="layui-inline">
		      <div class="layui-input-inline">
		        <input type="checkbox" name="RunState" id="RunState" lay-skin="switch" lay-filter="RunState" lay-text="永久|默认">
		      </div>
		    </div>
		  </div>
		  
		  <div class="layui-form-item">
		    <div class="layui-inline">
		      <label class="layui-form-label">间隔时长</label>
		      <div class="layui-input-inline">
		        <input type="number" name="Interval" id="Interval" lay-verify="required" autocomplete="off" class="layui-input" min="1">
		      </div>
		      <div class="layui-form-mid layui-word-aux">默认单位:分钟</div>
		    </div>
		  </div>
          
		  <div class="layui-form-item">
		   <div class="layui-input-block">
		     <button type="submit" class="layui-btn" lay-submit="" lay-filter="go" id="go">立即提交</button>
		     <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		   </div>
		 </div>
       </form>
		

		<script src="js/jquery.min.js"></script>
		<script src="layui/layui.js"></script>
        <script>
        layui.use(['layer','form'], function () {
            var layer = layui.layer, 
                form = layui.form;
            
            form.on('switch(RunState)',function(data){
            	if (this.checked === true)
            		$("#Duration").attr('disabled',true);
            	else 
            		$("#Duration").attr('disabled',false);
            })
            
            form.on('submit(go)', function (data) {
            	if($("#Content").val().trim() == "" || $("#Content").val().trim() == null){
            		layer.msg("请填写跑马灯内容");
            		return false;
            	}
            	if(data.field.RunState != 'on' && $("#Duration").val() == ""){
            		layer.msg("请填写播放时长",{icon:6});
            		return false;
            	}
            	
            	$.ajax({
            		type:'post',
            		url:"Runnotice/add",
            		data:{
            			content:$("#Content").val().trim(),
            			time:data.field.RunState === 'on'?0:$("#Duration").val(),
            			interval:$("#Interval").val()
            		},
            		success:function(data){
	            	    if(data == "success"){
	            			layer.msg("发布公告成功",{icon:1});
	            			setTimeout(function(){
	            				window.location.reload();
	            			},1000);
            			}else{
            				layer.msg(data,{icon:2});
            			}
            		},error:function(){
            			layer.msg("发布公告失败");
            		}
            	});
              return false;
            });
            });
        </script>
	</body>

</html>
